package com.igeek.domain;

import java.util.List;

public class Page {
    //总条数
    private int total;
    //每页展示条数
    private int size;
    //总页数
    private int count;
    //当前页码
    private int currentPage;
    //当前页的数据
    private List<?> data;
    //分页条
    private int [] bar;

    public Page() {
    }

    public Page(int total, int size, int count, int currentPage, List<?> data) {
        this.total = total;
        this.size = size;
        this.count = count;
        this.currentPage = currentPage;
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }

    public int[] getBar() {
        //起始值
        int start;
        //结束值
        int end;
        //当总页数小于9的时候
        if(count<9){
            start=1;
            end=count;
        }else{
            start=currentPage-5;
            end=currentPage+4;
            //如果结束页码已经大于总页码,这个时候结束值只能是总页码值
            if(currentPage+4>=count){
                start=count-9;
                end=count;
            }
            //如果起始页码已经小于1,那么起始页码就是1
            if(currentPage-5<1){
                start=1;
                end=10;
            }
        }
        //定义数组存放页码值
        bar=new int[end-start+1];
        //定义一个下标
        int index=0;
        for(int i=start;i<=end;i++){
            bar[index]=i;
            index++;
        }
        return bar;
    }

    public void setBar(int[] bar) {
        this.bar = bar;
    }
}
